package cn.ococci.dm.WiFi;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiManager;

import java.util.List;

import cn.ococci.dm.Main.Tools.LogTool;
import cn.ococci.dm.Network.HttpCallback;


/**
 * Created by cyan on 15/12/29.
 */
public class ScanWiFiBroadcastReceiver extends BroadcastReceiver {


    private HttpCallback callback;

    private WifiManager wm;


    public ScanWiFiBroadcastReceiver(WifiManager wm, HttpCallback<ScanResult> callback) {
        this.wm = wm;
        this.callback = callback;
    }

    @Override
    public void onReceive(Context context, Intent intent) {

        if (intent.getAction().equals(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION)) {

            List<ScanResult> scanResults = null;
            try {
                scanResults = wm.getScanResults();     // 得到扫描结果

            } catch (Exception e) {
                LogTool.log(LogTool.CYAN, "异常信息 :" + e.getMessage());
            }

            if (scanResults != null) {

                this.callback.onSuccessList(scanResults);
            }
        }
    }


}
